<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>demo</title>
    <script type="text/javascript" src="../vue.js"></script>
</head>

<body>
    <div id="app">
        <button @click="isHot = !isHot">改变天气</button>
        <h1>今天的天气真{{isHot?"热":"冷"}}</h1>
        <img :src="url" alt="">
        <h1>{{count}}</h1>
        <h1>{{person.name}}--{{person.age}}</h1>
        <button @click="person.age++">改变年龄</button>
    </div>
</body>
<script type="text/javascript">
    Vue.config.productionTip = false
    const vm = new Vue({
        el: "#app",
        data() {
            return {
                isHot: true,
                count: 0,
                url: "./re.webp",
                person: {
                    name: "laowang",
                    age: 19
                }
            }
        },
        watch: {
            isHot: {
                immediate: true,
                handler(a, b) {
                    this.count = a + 1
                    this.url = a ? "./re.webp" : "./leng.gif"
                }
            },
            person: {
                //对一个对象或者数组监视的时候,内部发送改变并不能触发handler 需要开启深度监视
                deep: true,
                handler() {
                    alert("你老了")
                }
            }
        }
    })
</script>

</html>